<!doctype html>
<html>
    
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
            <meta charset="UTF-8">
                <title>JS-SDK Demo</title>
                
                
                <link rel="stylesheet" href="//unpkg.com/layui@2.6.8/dist/css/layui.css">
                    <style rel="stylesheet" type="text/css" >.item{width:100wh;height:40px;}</style>
                    </head>
    <body>
        <div class="layui-tab">
            <ul class="layui-tab-title">
                <li class="layui-this">基础</li>
                <li>证书</li>
                <li>设备</li>
                <li>UI</li>
                <li>网络</li>
                <li>人脸核身</li>
                
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <div class = "item">
                        
                        <span class="">打印1</span>
                        <button class="" onclick= "consologBtn()">consologBtn</button>     <hr/>
                        
                    </div>
                    <div class = "item">
                        <span class="">传值给app</span>
                        <button class="" onclick= "print_ca('3333')">passByApp</button>     <hr/>
                        
                    </div>
                    
                </div>
                <div class="layui-tab-item">
                    <div class = "item">
                        <span class="">初始化手机盾001</span>
                        <button class="" onclick=initDun()>initDun</button>  <hr/>
                    </div>
                    <div class = "item">
                        <span class="">账户是否注册</span>
                        <button class="" onclick=isRegister()>isRegister</button>  <hr/>
                    </div>
                    <div class = "item">
                        <span class="">用户注册</span>
                        <button class="" onclick=register()>register</button>  <hr/>
                    </div>
                    <div class = "item">
                        <span class="">申请证书</span>
                        <button class="" onclick=applyCert()>applyCert</button>  <hr/>
                    </div>
                    <div class = "item">
                        <span class="">p1签名</span>
                        <button class="" onclick=p1GBSign()>p1GBSign</button>  <hr/>
                    </div>
                    <div class = "item">
                        <span class="">p7签名</span>
                        <button class="" onclick=p7Sign()>p7Sign</button>  <hr/>
                    </div>
                    <div class = "item">
                        <span class="">pin码修改</span>
                        <button class="" onclick=changePin()>changePin</button>  <hr/>
                    </div>
                    <div class = "item">
                        <span class="">pin码检查</span>
                        <button class="" onclick=checkPin()>checkPin</button>  <hr/>
                    </div>
                    <div class = "item">
                        <span class="">获取证书</span>
                        <button class="" onclick=getCert()>getCert</button>  <hr/>
                    </div>
                    <div class = "item">
                        <span class="">获取证书内容</span>
                        <button class="" onclick="getCertInfo()">getCertInfo</button>  <hr/>
                    </div>
                    <div class = "item">
                        <span class="">加密证书加密</span>
                        <button class="" onclick=encryptionCertEncrytion()>encryptionCertEncrytion</button>  <hr/>
                    </div>
                    <div class = "item">
                        <span class="">获取证书解密</span>
                        <button class="" onclick=encryptionCertDecrypt()>encryptionCertDecrypt</button>  <hr/>
                    </div>
                    <div class = "item">
                        <span class="">签名证书加密</span>
                        <button class="" onclick=signatureCertEncrytion()>signatureCertEncrytion</button>  <hr/>
                    </div>
                    <div class = "item">
                        <span class="">签名证书解密</span>
                        <button class="" onclick=signatureCertDecrypt()>signatureCertDecrypt</button>  <hr/>
                    </div>
                </div>
                
                <div class="layui-tab-item">
                    <div class = "item">
                        <span class="">设备信息</span>
                        <button class="" onclick=getDevice()>getDevice</button>  <hr/>
                    </div>
                    <div class = "" height="100" >
                        <span class="">打开相册</span>
                        <img class="img1" width="40" height="40" src="https://img0.baidu.com/it/u=2806874804,28969291&fm=224&fmt=auto&gp=0.jpg"  />
                        <button class="" onclick=openAlbum1()>openAlbum</button>  <hr/>
                    </div>
                    
                    <div class = "">
                        <span class="">拍照</span>
                        <img class="img2" width="40" height="40" src="https://img0.baidu.com/it/u=2806874804,28969291&fm=224&fmt=auto&gp=0.jpg"  />
                        <button class="" onclick=openCamera()>openAlbum</button>  <hr/>
                    </div>
                    
                    
                    <div class = "">
                        <span class="">视频</span>
                        <img class="img3" width="40" height="40" src=    "https://img0.baidu.com/it/u=2806874804,28969291&fm=224&fmt=auto&gp=0.jpg"  />
                        <button class="" onclick=openVideo()>openVideo</button>  <hr/>
                    </div>
                    
                    <div class = "item">
                        <span class="">根据文件路径播放视频</span>
                        <button class="" onclick=playVideo()>playVideo</button>  <hr/>
                    </div>
                    <div class = "item">
                        <span class="">扫码</span>
                        <button class="" onclick=scanQrCode()>scanQrCode</button>  <hr/>
                    </div>
                    
                    <div class = "item">
                        <span class="">检查某个权限是否开启</span>
                        <button class="" onclick=checkPremission()>checkPremission</button>  <hr/>
                    </div>
                    
                    <div class = "item">
                        <span class="">开启某个权限</span>
                        <button class="" onclick=openPremission()>openPremission</button>  <hr/>
                    </div>
                    
                    <div class = "item">
                        <span class="">批量开启权限</span>
                        <button class="" onclick=openPremissions()>openPremissions</button>  <hr/>
                    </div>
                    <div class = "item">
                        <span class="">获取位置信息</span>
                        <button class="" onclick=getLocationInfo()>getLocationInfo</button>  <hr/>
                    </div>
                    
                    <div class = "item">
                        <span class="">存数据</span>
                        <button class="" onclick=saveCache()>saveCache</button>  <hr/>
                    </div>
                    
                    <div class = "item">
                        <span class="">取数据</span>
                        <button class="" onclick=readCache()>readCache</button>  <hr/>
                    </div>
                    
                    <div class = "item">
                        <span class="">根据key清理数据</span>
                        <button class="" onclick=removeCache()>removeCache</button>  <hr/>
                    </div>
                    
                    
                </div>
                <div class="layui-tab-item">
                    <div class = "item">
                        <span class="">toast</span>
                        <button class="" onclick= showToast()>showToast</button>  <hr/>
                    </div>
                    <div class = "item">
                        <span class="txt-title">alert</span>
                        <button class="" onclick=showAlert()>showAlert</button>  <hr/>
                    </div>
                    
                    <div class = "item">
                        <span class="">关闭当前页</span>
                        <button class="" onclick=closeWeb()>closeWeb</button>  <hr/>
                    </div>
                    <div class = "item">
                        <span class="">显示导航栏</span>
                        <button class="" onclick=showNav()>showNav</button>  <hr/>
                    </div >
                    <div class = "item">
                        <span class="">隐藏导航栏</span>
                        <button class="" onclick=hideNav()>hideNav</button>  <hr/>
                    </div>
                   
                    <div class = "item">
                        <span class="">打开原生界面</span>
                        <button class="" onclick=openNativeActivity()>openNativeActivity</button>  <hr/>
                    </div>
                    
                    <div class = "item">
                        <span class="">打开商店指定页面</span>
                        <button class="" onclick=openStorePage()>openStorePage</button>  <hr/>
                    </div>
                    
                    <div class = "item">
                        <span class="">获取当前网络状态</span>
                        <button class="" onclick=getNetStatus()>getNetStatus</button>  <hr/>
                    </div>
                    <div class = "item">
                        <span class="">初始化全屏进度条</span>
                        <button class="" onclick=openFullScreenProgress()>openFullScreenProgress</button>  <hr/>
                    </div>
                    
                    <div class = "item">
                        <span class="">停止进度条</span>
                        <button class="" onclick=stopProgressBar()>stopProgressBar</button>  <hr/>
                    </div>
                    <div class = "item">
                        <span class="">action sheet</span>
                        <button class="" onclick=actionsheet()>actionsheet</button>  <hr/>
                    </div>
                    
                </div>
                
                <div class="layui-tab-item">
                    <div class = "item">
                        <span class="">post请求</span>
                        <button class="" onclick= network('POST')>post</button>  <hr/>
                    </div>
                     <div class = "item">
                        <span class="">get请求</span>
                        <button class="" onclick= network('GET')>get</button>  <hr/>
                    </div>
                    <div class = "item">
                        <span class="">文件上传</span>
                        <button class="" onclick= uplood()>uplood</button>  <hr/>
                    </div>
                </div>
                

            <div class="layui-tab-item ">
                    <div class = "item">
                        
                        <span class="">身份证识别正面</span>
                        <button class="" onclick= openOcr() >openOcr</button>     <hr/>
                        
                    </div>
                    
                     <div class = "item">
                        
                        <span class="">身份证识别背面</span>
                        <button class="" onclick= openOcrBack() >openOcrBack</button>     <hr/>
                        
                    </div>
                    <div class = "item">
                        <span class="">人脸识别</span>
                        <button class="" onclick=openFace() >openFace</button>     <hr/>
                        
                    </div>
                    
                </div>

                
            </div>
        </div>
        
        
        
        
        
        
        
        
    </body>
    
    <script src="//unpkg.com/layui@2.6.8/dist/layui.js"></script>
    
    
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script type="text/javascript" src="CAJssdk.js"></script>
    <script type="text/javascript" src="eruda.js"></script>
    
    <script>
        
        eruda.init()
        
        
        var k_pin = "123456"
        var username = "380001"
        function initDun(){
            
       
            caSdk.dun.init(username,function(data){
                let callResultJson =  JSON.parse(data)
                console.log("-----",callResultJson)
            })
            
        }

       function openOcr(){

                let cardType = new OCR_CARDTYPE()
           
            caSdk.openOcr(cardType.front,function(data){
                let callResultJson =  JSON.parse(data)
                console.log("-----",callResultJson)
            });
       }

       function openOcrBack(){
           let cardType = new OCR_CARDTYPE()
           
            caSdk.openOcr(cardType.back,function(data){
                let callResultJson =  JSON.parse(data)
                console.log("-----",callResultJson)
            });
       }
       function openFace(){
           let name = "程元平";
           let cardId = "36233019890321825X"
            caSdk.openFace(cardId,name,function(data){
                let callResultJson =  JSON.parse(data)
                console.log("-----",callResultJson)
            });
       }



       function network(requestType){
            console.log(requestType)
       
            if(requestType == 'POST'){
                 let params = {"userName":"成都","age":"f51d665d9242ce03a07dde11280ae133"}
                let urlSting = "http://192.168.1.58:8080/user/testJson";
                let headers = {"Content-Type":"application/json;charset=UTF-8"}
                 caSdk.request(urlSting,params,method_request.POST,headers,function(data){
                    console.log("----进来1")
                let callResultJson =  JSON.parse(data)
                console.log("-----",callResultJson)
                })
        }else{
               let params = {"userName":"成都","age":"f51d665d9242ce03a07dde11280ae133"}
                 let urlSting = "http://192.168.1.58:8080/user/test";
                
                 caSdk.request(urlSting,params,method_request.GET,null,function(data){
                    console.log("----进来1")
                let callResultJson =  JSON.parse(data)
                console.log("-----",callResultJson)
                })
        }
       }
        function uplood(){

//             caSdk.openAlbum(function (data) {
//
//
//            let callResultJson =  JSON.parse(data)
//
//
//            console.log("filePath------","file://"+callResultJson.data.filePath)
//
//             var filePath = "file://" + callResultJson.data.filePath
//             filePath = "file:///var/containers/Bundle/Application/F6078C29-50D6-407C-8DF9-141500AA0D1F/bridging_js.app/back_grey_scca_001.png"
//            upload("http://192.168.1.59:8080/user/upload",{file:filePath},"001.png")
//          })
             var filePath = "file:///var/containers/Bundle/Application/F6078C29-50D6-407C-8DF9-141500AA0D1F/bridging_js.app/back_grey_scca_001.png"
            upload("http://192.168.1.59:8080/user/upload",{file:filePath},"001.png")

        }

        
        function actionsheet(){
            let content = ["001","002","003"]
       
            caSdk.actionsheet("标题",content,function(data){
                let callResultJson =  JSON.parse(data)
                console.log("-----",callResultJson)
            })
        }
    function isRegister(){
        console.log("----:---");
        
        caSdk.dun.isRegister(function(data){
            let callResultJson =  JSON.parse(data)
            console.log("-----",callResultJson)
        })
    }
    function register(){
        caSdk.dun.register(function(data){
            let callResultJson =  JSON.parse(data)
            console.log("-----",callResultJson)
        })
        
    }
    function applyCert(){
        caSdk.dun.apply(k_pin,function(data){
            let callResultJson =  JSON.parse(data)
            console.log("-----",callResultJson)
        })
    }
    function p1GBSign(){
        console.log("-----")
        caSdk.dun.p1Sign("chtestori",k_pin,false,function(data){
            let callResultJson =  JSON.parse(data)
            console.log("-----",callResultJson)
        })
        
    }
    function p7Sign(){
        caSdk.dun.p7Sign("chtestori",k_pin,function(data){
            let callResultJson =  JSON.parse(data)
            console.log("-----",callResultJson)
        })
    }
    function changePin(){
        caSdk.dun.changePin(k_pin,k_pin,function(data){
            let callResultJson =  JSON.parse(data)
            console.log("-----",callResultJson)
        })
    }
    function checkPin(){
        caSdk.dun.checkPin(k_pin,function(data){
            let callResultJson =  JSON.parse(data)
            console.log("-----",callResultJson)
        })
    }
    function getCert(){
        caSdk.dun.getCert(function(data){
            let callResultJson =  JSON.parse(data)
            console.log("-----",callResultJson)
        })
        
    }
    function getCertInfo(){
        console.log("-----")
        caSdk.dun.getCertInfo(function(data){
            let callResultJson =  JSON.parse(data)
            console.log("-----",callResultJson)
        })
    }
    var encResult
    function encryptionCertEncrytion(){
        caSdk.dun.encCertEnc("mytest",function(data){
            let callResultJson =  JSON.parse(data)
            encResult = callResultJson.data.ciphertext
            console.log("-----",callResultJson)
            
            console.log("---encResult--",encResult)
        })
        
    }
    function encryptionCertDecrypt(){
        
        caSdk.dun.encCertDec(encResult,k_pin,function(data){
            let callResultJson =  JSON.parse(data)
            
            console.log("-----",callResultJson)
            
            
        })
    }
    
    var signOri
    function signatureCertEncrytion(){
        console.log("---001")
        caSdk.dun.signCertEnc("signori",function(data){
            let callResultJson =  JSON.parse(data)
            signOri = callResultJson.data.ciphertext
            console.log("-----",callResultJson)
            
            
        })
        
    }
    function signatureCertDecrypt(){
        caSdk.dun.signCertDec(signOri,k_pin,function(data){
            let callResultJson =  JSON.parse(data)
            
            console.log("-----",callResultJson)
            
            
        })
        
    }
    
    
    
    function stopProgressBar(){
        caSdk.progressBar.stop()
    }
    function openFullScreenProgress(){
        
        //初始化进度条
        var barStyle = new PROCESSBAR_Style();
        
        barStyle.deaultColor = "#FFB400"
        barStyle.trackColor = "#DC143C"
        barStyle.percentColor = "#DC143C"
        caSdk.progressBar.init(barStyle);
        
        
        var i = 0
        var timer = setInterval(function () {
            i += 0.05
            
            caSdk.progressBar.start(i)
            if(i >= 1){
                
                clearInterval(timer)
            }
        },100);
        
        
        
        
        
    }
    function removeCache(){
        caSdk.removeCache("testKey1",function(data){
            let callResultJson =  JSON.parse(data)
            console.log("-----",callResultJson)
        })
    }
    function saveCache(){
        
        let valueMap = {test:"001",test2:"3333"}
        
        
        caSdk.saveCache("testKey1",valueMap,function(data){
            let callResultJson =  JSON.parse(data)
            console.log("-----",callResultJson)
        })
    }
    
    function readCache(){
        
        caSdk.readCache("testKey1",function(data){
            let callResultJson =  JSON.parse(data)
            console.log("-----",callResultJson)
        })
    }
    
    function getLocationInfo(){
        caSdk.getLocationInfo(function(data){
            let callResultJson =  JSON.parse(data)
            console.log("-----",callResultJson)
        })
    }
    
    function checkPremission(){
        caSdk.checkPremission(ANDROID_PERMISSIONS.WRITE_EXTERNAL_STORAGE,function(data){
            let callResultJson =  JSON.parse(data)
            console.log("-----",callResultJson)
        })
    }
    
    function openPremission(){
        caSdk.openPremission(ANDROID_PERMISSIONS.WRITE_EXTERNAL_STORAGE,function(data){
            let callResultJson =  JSON.parse(data)
            console.log("-----",callResultJson)
        })
    }
    
    function openPremissions(){
        caSdk.openPremissions([ANDROID_PERMISSIONS.CAMERA,ANDROID_PERMISSIONS.WRITE_EXTERNAL_STORAGE],function(data){
            let callResultJson =  JSON.parse(data)
            console.log("-----",callResultJson)
        })
    }
    
    function getNetStatus(){
        
        console.log("-----")
        caSdk.getNetStatus(function(data){
            let callResultJson =  JSON.parse(data)
            console.log("-----",callResultJson)
        })
    }
    
    
    function openStorePage(){
        var storeUrl
        if(isAndorid()){
            storeUrl = ""
        }else{
            storeUrl = "https://apps.apple.com/cn/app/%E9%92%9C%E4%BF%A1%E7%AD%BE/id1549118223"
        }
        caSdk.openStorePage(storeUrl)
    }
    
    
    function openNativeActivity(){
        
        caSdk.openNativeActivity("TestAC",function(data){
            let callResultJson =  JSON.parse(data)
            console.log("-----",callResultJson)
            
            
        })
    }
    function openAlbum1(){
        
        caSdk.openAlbum(function (data) {
            
            
            let callResultJson =  JSON.parse(data)
            
            $('.img1').attr('src',"data:image/png;base64,"+callResultJson.data.base64);

            console.log("filePath------","file://"+callResultJson.data.filePath)

        
        })
        
    }
    
    
    
    function scanQrCode(){
        caSdk.scanQrCode(function(data){
            let callResultJson =  JSON.parse(data)
            console.log("-----",callResultJson)
            
            
        })
    }
    
    function openCamera(){
        caSdk.openCamera(function (data) {
            let callResultJson =  JSON.parse(data)
            
            
            console.log("-----",callResultJson.data.base64)
            $('.img2').attr('src',"data:image/png;base64,"+callResultJson.data.base64);
            
            console.log(data)
        })
        
    }
    
    function openVideo(){
        caSdk.openVideo(function (data) {
            let callResultJson =  JSON.parse(data)
            
            
            console.log("-----",callResultJson.data.base64)
            
            console.log(data)
        })
    }
    function playVideo(){
        caSdk.playVideo("https://haokan.baidu.com/v?pd=wisenatural&vid=15083070681949534270")
    }
    
    function consologBtn(){
        
        console.log('测试打印')
        caSdk.print("打印")
    }
    function showToast(){
        
        caSdk.toast("toasttiiiii")
    }
    
    
    
    function showAlert(){
        
        var alertParam = new CA_alert_param();
        alertParam.title = "提示标题1"
        alertParam.body = "内容"
        alertParam.leftName  = "取消1"
        alertParam.rightName = "确定1"
        alertParam.singleName= ""
        
        caSdk.alert(alertParam,function (data) {
            console.log(data)
            $('.txt-title').text("确定成功");
        },function (data) {
            $('.txt-title').text("取消成功");
            
        })
    }
    function closeWeb(){
        caSdk.closeWeb()
    }
    
    function showNav(){
        
        
        var caStyle = new CA_Style();
        
        caStyle.bgColor = "#FFB400"
        caStyle.textColor = "#DC143C"
        caStyle.textSize = 15
        
        
        var title = "导航栏title-00-"
        
        
        caSdk.showNav(title,caStyle)
        
    }
    
    function hideNav(){
        caSdk.hideNav()
    }
    
    function getDevice(){
        
        caSdk.getDeviceInfo(function (data) {
            
            console.log(data)
        })
    }

   function upload(url,params,fileName){
    var formData = new FormData();
//    for (var key in params) {
//      formData.append(key, params[key]);
//    }
    var file = {
      uri: params.file,
      type: 'multipart/form-data',
      name: fileName,
    };
    console.log("---file",file)
    formData.append('file', file);

    var xhr = new XMLHttpRequest();
       xhr.onreadystatechange = (e) => {
       console.log('--------xhr-------', xhr);
       console.log("-----eeee----",e)
       console.log('--------status-------', xhr.status);
      if (xhr.readyState !== 4) {
        return;
      }
      if (xhr.status === 200) {
        console.log('请求成功！');

        console.log(JSON.parse(xhr._response))
      } else {
        console.log('请求失败！');
      
      }
    };
    xhr.open('POST', url);
    xhr.setRequestHeader('Content-Type', 'multipart/form-data;boundary=------WWWWWWKKDFHDKFHDDH;charset=utf-8');
    xhr.send(formData);
    if (xhr.upload) {
      console.log('xhr.upload', xhr.upload);
      xhr.upload.onprogress = ({total, loaded}) => {
        let percent = loaded / total;
        DeviceEventEmitter.emit('onProgress', percent);
        // this.props.onProgress(percent);
        console.log('loaded / total', loaded / total);
      };
    }
}

    
        </script>
    
    
    
    
</html>
